<template>
	<view >
		<view class='order-details'>
			<view>
				<view class='header acea-row row-middle' :class='invoiceData.status==2 ? "on":""'>
					<view class='pictrue'>
						<i class="iconfont icon-fapiao fapiao"></i>
					</view>
					<view class='data'>
						<view class='state'>
							<block >{{invoiceData.statusDesc}}</block>
						</view>
						<view>申请时间：{{invoiceData.addTimeDesc}}</view>
					</view>
				</view>
				<view class='wrapper'>
					<view class='item acea-row row-between'>
						<view>发票类型：</view>
						<view class='conter'>{{invoiceData.typeDesc}}</view>
					</view>
					<view v-if="invoiceData.headerType == 2" class='item acea-row row-between'>
						<view>发票内容：</view>
						<view class='conter'>{{invoiceData.dutyNumber}}</view>
					</view>
					<view class='item acea-row row-between'>
						<view>抬头类型：</view>
						<view class='conter'>{{invoiceData.headerTypeDesc}}</view>
					</view>
					<view class='item acea-row row-between'>
						<view>抬头名称：</view>
						<view class='conter'>{{invoiceData.name}}</view>
					</view>
					<view v-if="invoiceData.statusTimeDesc" class='item acea-row row-between'>
						<view>开票时间：</view>
						<view class='conter'>{{invoiceData.statusTimeDesc}}</view>
					</view>
					<view class='item acea-row row-between'>
						<view>申请时间：</view>
						<view class='conter'>{{invoiceData.addTimeDesc}}</view>
					</view>
				</view>

			
			</view>
			 <!-- //如果是企业普票 -->
			<view class='wrapper' v-if="invoiceData.headerType == 2 && invoiceData.type == 1">
				<view v-if="invoiceData.inUrl" class='item acea-row row-between'>
					<view>发票链接：</view>
					<view class='conter acea-row row-middle row-right'>
						<view class="text-ellipsis">
							{{invoiceData.inUrl}}
						</view>
						<!-- #ifndef H5 -->
						<text class='copy' @tap='copy'>复制</text>
						<!-- #endif -->
						<!-- #ifdef H5 -->
						<text class='copy copy-data' :data-clipboard-text="invoiceData.inUrl">复制</text>
						<!-- #endif -->
					</view>
				</view>
				<view v-if="invoiceData.inQrcode"  class='item acea-row row-between'>
					<view>发票图片：</view>
					<view class="display-flex-column" style="align-items: end;">
						<view @click="preImage(invoiceData.inQrcode)" class='conter acea-row row-middle row-right'>
							<image :src="invoiceData.inQrcode" style="height: 150px;" />
						</view>
						<view class='grey-button'style="margin-top: 10px;width: 80px;" @click.stop='uploadpic'>重新上传</view>
					</view>
					
				</view>
				<view v-if="!invoiceData.inQrcode"  class='item acea-row row-between'>
					<view>发票图片：</view>
					<image @click.stop='uploadpic'  src="../../../static/images/tjzp.png"  style="width: 50px;height: 50px;" ></image>
					
				</view>
				
			</view>
			
			 <!-- //如果是企业专票 -->
			<view class='wrapper' v-if="invoiceData.headerType == 2 && invoiceData.type == 2">
				<view  v-if="invoiceData.specialType == 1" class='item acea-row row-between'>
					<view>快递公司：</view>
					<view class='conter'>{{invoiceData.devCompany}}</view>
				</view>
				<view  v-if="invoiceData.specialType == 1"  class='item acea-row row-between'>
					<view>快递单号：</view>
					<view class='conter acea-row row-middle row-right'>
						<view class="text-ellipsis">
							{{invoiceData.devCode}}
						</view>
						<!-- #ifndef H5 -->
						<text class='copy' @tap='copyDev'>复制</text>
						<!-- #endif -->
				
					</view>
				</view>
				<view  v-if="invoiceData.specialType == 1"  class='item acea-row row-between'>
					<view>邮寄地址：</view>
					<view class='conter acea-row row-middle row-right'>
						<view class="text-ellipsis">
							{{invoiceData.postAddress}}
						</view>

					</view>
				</view>
				<view  v-if="invoiceData.specialType == 2" class='item acea-row row-between'>
					<view>自取地址：</view>
					<view class='conter'>{{invoiceData.companyAddress}}</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>

	let app = getApp();
	import { HTTP_REQUEST_URL } from '@/config/app';
	
	
	import { getBaocheInvoiceDetail, updateBaocheInvoice} from '@/api/api.js';


	import ClipboardJS from "@/plugin/clipboard/clipboard.js";
	import { mapGetters } from "vuex";
	export default {
		components: {
		},
		data() {
			return {
				invoiceData: '',
				baoche_id: '',
				order_id: '',
				invoice_id: '',
				evaluate: 0,
				activityType: 0,
				cartInfo: [], //购物车产品
				orderInfo: {
					system_store: {},
					_status: {},
					take: {}
				}, //订单详情
				orderData: {},
				system_store: {},
				isGoodsReturn: false, //是否为退款订单
				status: {}, //订单底部按钮状态
				isClose: false,
				pay_close: false,
				pay_order_id: '',
				totalPrice: '0',
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				refundNum: [], //退款个数临时数据
				imgUrl:HTTP_REQUEST_URL,
				codeUrl:'',
				isTimePay: false,
				receipt_info: {},
			};
		},
		computed:{
			...mapGetters(['isLogin','uid']),
		},
		filters:{
			filterDay(val){
				if(val){
					var reg =/(\d{4})\-(\d{2})\-(\d{2})/;
					var date = val.replace(reg,"$2月$3日");
					return date
				}
			}
		},
		onLoad: function(options) {
			if (options.baoche_id) {
				this.$set(this, 'baoche_id', options.baoche_id);
			}
		},
		onShow() {
			if (this.isLogin) {
				this.getOrderInfo();
			} else {
                this.isAuto = true;
                this.isShowAuth = true
			}

		},
		onHide: function() {
			this.isClose = true;
		},
		onReady: function() {
			// #ifdef H5
			this.$nextTick(function() {
				const clipboard = new ClipboardJS(".copy-data");
				clipboard.on("success", () => {
					this.$util.Tips({
						title: '复制成功'
					});
				});
			});
			// #endif
		},
		methods: {
			/**
			 * 上传文件
			 * 
			 */
			uploadpic: function() {
				let that = this;
				that.$util.uploadImageOne({
					url: 'upload/image',
					name: 'multipart',
					model: "maintain",
					pid: 0
				}, function(res) {
					updateBaocheInvoice({
						id: that.invoiceData.id,
						inQrcode: res.data.url,
						}).then(res2 => {
					// let _type = res.data._status._type;
						that.invoiceData.inQrcode = res.data.url;
						
					}).catch(err => {
						that.$util.Tips({
							title: err
						});
					});
					
				});
			},
			preImage(imagesBase64){
				uni.previewImage({
					current: 0,
					urls: [imagesBase64],
					longPressActions: {
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			
			// 保存图片
			onSaveImg() {
				const that = this;
	
				uni.showLoading({
					title: '图片下载中'
				});
				uni.getSetting({
					success: res => {
						console.log(222,res)
						that.saveImageToPhotosAlbumFun()
						if (res.authSetting['writePhotosAlbum']) {
							// that.saveImageToPhotosAlbumFun()
						} else {
							// uni.authorize({
							// 	scope: 'writePhotosAlbum',
							// 	success: () => {
							// 		that.saveImageToPhotosAlbumFun()
							// 	},
							// 	fail: () => {
							// 		uni.showModal({
							// 			title: '提示',
							// 			content: '请先在设置页面打开“保存相册”使用权限',
							// 			confirmText: '去设置',
							// 			cancelText: '算了',
							// 			success: data => {
							// 				if (data.confirm) {
							// 					uni.openSetting();
							// 				}
							// 				uni.hideLoading();
							// 			}
							// 		});
							// 	},
							// 	complete: res => {
							// 		console.log("res",res)
							// 		uni.hideLoading();
							// 	}
							// });
						}
					}
				});
			},
			saveImageToPhotosAlbumFun() {
				const that = this;
				uni.downloadFile({
					url: that.invoiceData.inQrcode, //图片的地址
					success: function(res) {
						const tempFilePath = res.tempFilePath //通过res中的tempFilePath 得到需要下载的图片地址
						uni.saveImageToPhotosAlbum({
							filePath: tempFilePath,
							success: () => {
								uni.hideLoading();
								uni.showToast({
									title: '图片已保存到相册'
								});
							},
							fail: () => {
								uni.showToast({
									title: '保存失败',
									icon: 'error'
								});
							},
							complete: res => {
								uni.hideLoading();
							}
						});
					}
				})
			},
			call: function(){
				uni.makePhoneCall({
					phoneNumber: this.orderData.merchant.service_phone
				})
			},
			// 联系客服
			goGoodCall() {
				let self = this
				uni.navigateTo({
					url: `/pages/chat/customer_list/chat?mer_id=${self.orderInfo.mer_id}&uid=${this.uid}&order_id=${self.orderInfo.order_id}`
				})
			},

			/**
			 * 事件回调
			 *
			 */
			onChangeFun: function(e) {
				let opt = e;
				let action = opt.action || null;
				let value = opt.value != undefined ? opt.value : null;
				(action && this[action]) && this[action](value);
			},
			/**
			 * 拨打电话
			 */
			makePhone: function() {
				uni.makePhoneCall({
					phoneNumber: this.orderInfo.take.mer_take_phone
				})
			},

			/**
			 * 关闭支付组件
			 *
			 */
			payClose: function() {
				this.pay_close = false;
			},
			/**
			 * 登录授权回调
			 *
			 */
			onLoadFun: function() {
				this.isShowAuth = false;
				this.getOrderInfo();
			},
            // 授权关闭
            authColse: function(e) {
                this.isShowAuth = e;
            },
			getOrderCode(){
				verifyCode(this.order_id).then(res=>{
					this.codeUrl = res.data.qrcode
				})
			},
			/**
			 * 获取订单详细信息
			 *
			 */
			getOrderInfo: function() {
				let that = this;
				uni.showLoading({
					title: "正在加载中"
				});
				getBaocheInvoiceDetail({baocheId: this.baoche_id}).then(res => {
					// let _type = res.data._status._type;
					uni.hideLoading();
					that.invoiceData = res.data
					
				}).catch(err => {
					uni.hideLoading();
					that.$util.Tips({
						title: err
					});
				});
			},
			/**
			 *
			 * 剪切订单号
			 */
			// #ifndef H5
			copy: function() {
				let that = this;
				uni.setClipboardData({
					data: that.invoiceData.inUrl,
					success: function(res){
						that.$util.Tips({
							title: "复制成功"
						});
					}
				});
			},
			// #endif
			
			copyDev(){
				let that = this;
				uni.setClipboardData({
					data: that.invoiceData.devCode,
					success: function(res){
						that.$util.Tips({
							title: "复制成功"
						});
					}
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.merchant {
		width: 100%;
		height: 86rpx;
		padding: 0 30rpx;
		margin-top: 15rpx;
		border-bottom: 2rpx solid #f0f0f0;
		font-size: 30rpx;
		color: #282828;
		line-height: 86rpx;
		box-sizing: border-box;
		background-color: #fff;
		.iconfont {
			margin-top: 6rpx;
			font-size: 22rpx;
		}
	}
	.goodCall {
		text-align: center;
		width: 100%;
		height: 86rpx;
		padding: 0 30rpx;
		border-bottom: 1rpx solid #eee;
		font-size: 30rpx;
		line-height: 86rpx;
		background: #fff;
		color: #282828;
		.icon-kefu {
			font-size: 28rpx;
			margin-right: 15rpx;
		}
		/* #ifdef MP */
		button {
			display: flex;
			align-items: center;
			justify-content: center;
			height: 86rpx;
			font-size: 30rpx;
			color: #e93323;
		}
		/* #endif */
	}
	.order-details .header {
		padding: 0 30rpx;
		height: 150rpx;
		background-image: linear-gradient(-90deg, #F11B09 0%, #F67A38 100%);
		&.presell_header{
			background-image: url('');
			background-repeat: no-repeat;
			background-size: cover;
			padding: 35rpx 50rpx;
			.data{
				margin: 8rpx 0 0 13rpx;
				.state{
					font-weight: normal;
					font-size: 24rpx;
				}
			}
		}
	}
	.order-details .header.on {
		background-color: #666 !important;
	}
	.order-details .header .pictrue {
		width: 110rpx;
		height: 110rpx;
	}
	.order-details .header .pictrue .fapiao {
		width: 100%;
		height: 100%;
		color: #fff;
		font-size: 80rpx
	}
	.order-details .header .data {
		color: rgba(255, 255, 255, 0.8);
		font-size: 24rpx;
		margin-left: 27rpx;
	}
	.order-details .header .data.on {
		margin-left: 0;
	}
	.order-details .header .data .state {
		font-size: 30rpx;
		font-weight: bold;
		color: #fff;
		margin-bottom: 7rpx;
	}
	.presell_header .presell_payment{
		color: #fff;
		font-size: 30rpx;
		font-weight: bold;
		.iconfont{
			font-weight: normal;
			margin-right: 8rpx;
		}
	}
	.order-details .header .data .time {
		margin-left: 20rpx;
	}
	.order-details .nav {
		background-color: #fff;
		font-size: 26rpx;
		color: #282828;
		padding: 25rpx 0;
	}
	.order-details .nav .navCon {
		padding: 0 40rpx;
	}
	.order-details .nav .on {
		color: #e93323;
	}
	.order-details .nav .progress {
		padding: 0 65rpx;
		margin-top: 10rpx;
	}
	.order-details .nav .progress .line {
		width: 100rpx;
		height: 2rpx;
		background-color: #939390;
	}
	.order-details .nav .progress .iconfont {
		font-size: 25rpx;
		color: #939390;
		margin-top: -2rpx;
	}
	.order-details .address {
		font-size: 26rpx;
		color: #868686;
		background-color: #fff;
		margin-top: 13rpx;
		padding: 35rpx 30rpx;
	}
	.order-details .address .name {
		font-size: 30rpx;
		color: #282828;
		margin-bottom: 15rpx;
	}
	.order-details .address .name .phone {
		margin-left: 40rpx;
	}
	.order-details .line {
		width: 100%;
		height: 3rpx;
	}
	.order-details .line image {
		width: 100%;
		height: 100%;
		display: block;
	}
	.order-details .wrapper {
		background-color: #fff;
		margin-top: 12rpx;
		padding: 30rpx;
	}
	.order-details .wrapper .item {
		font-size: 28rpx;
		color: #282828;
	}
	.order-details .wrapper .item~.item {
		margin-top: 20rpx;
	}
	.order-details .wrapper .item .conter {
		color: #868686;
		width: 460rpx;
		text-align: right;
	}
	.order-details .wrapper .item .conter .copy {
		font-size: 20rpx;
		color: #333;
		border-radius: 17rpx;
		border: 1rpx solid #666;
		padding: 3rpx 15rpx;
		margin-left: 24rpx;
		margin-top: 10px;
	}
	.order-details .wrapper .actualPay {
		border-top: 1rpx solid #eee;
		margin-top: 30rpx;
		padding-top: 30rpx;
	}
	.order-details .wrapper .actualPay .money {
		font-weight: bold;
		font-size: 30rpx;
	}
	.order-details .footer {
		width: 100%;
		height: 100rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #fff;
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.order-details .footer .bnt {
		width: 176rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		border-radius: 50rpx;
		color: #fff;
		font-size: 27rpx;
		margin-left: 20rpx;
		&.btn_auto{
			width: auto;
			padding: 0 40rpx;
		}
	}
	.order-details .footer .bnt.cancel {
		color: #aaa;
		border: 1rpx solid #ddd;
	}
	.order-details .footer .bnt~.bnt {
		margin-left: 18rpx;
	}
	.order-details .writeOff {
		background-color: #fff;
		margin-top: 13rpx;
		padding-bottom: 30rpx;
	}
	.order-details .writeOff .title {
		font-size: 30rpx;
		color: #282828;
		height: 87rpx;
		border-bottom: 1px solid #f0f0f0;
		padding: 0 30rpx;
		line-height: 87rpx;
	}
	.order-details .writeOff .grayBg {
		background-color: #f2f5f7;
		width: 590rpx;
		height: 384rpx;
		border-radius: 20rpx 20rpx 0 0;
		margin: 50rpx auto 0 auto;
		padding-top: 55rpx;
	}
	.order-details .writeOff .grayBg .pictrue {
		width: 290rpx;
		height: 290rpx;
		margin: 0 auto;
	}
	.order-details .writeOff .grayBg .pictrue image {
		width: 100%;
		height: 100%;
		display: block;
	}
	.order-details .writeOff .gear {
		width: 590rpx;
		height: 30rpx;
		margin: 0 auto;
	}
	.order-details .writeOff .gear image {
		width: 100%;
		height: 100%;
		display: block;
	}
	.order-details .writeOff .num {
		background-color: #f0c34c;
		width: 590rpx;
		height: 84rpx;
		color: #282828;
		font-size: 48rpx;
		margin: 0 auto;
		border-radius: 0 0 20rpx 20rpx;
		text-align: center;
		padding-top: 4rpx;
	}
	.order-details .writeOff .rules {
		margin: 46rpx 30rpx 0 30rpx;
		border-top: 1px solid #f0f0f0;
		padding-top: 10rpx;
	}
	.order-details .writeOff .rules .item {
		margin-top: 20rpx;
	}
	.order-details .writeOff .rules .item .rulesTitle {
		font-size: 28rpx;
		color: #282828;
	}
	.order-details .writeOff .rules .item .rulesTitle .iconfont {
		font-size: 30rpx;
		color: #333;
		margin-right: 8rpx;
		margin-top: 5rpx;
	}
	.order-details .writeOff .rules .item .info {
		font-size: 28rpx;
		color: #999;
		margin-top: 7rpx;
	}
	.order-details .writeOff .rules .item .info .time {
		margin-left: 20rpx;
	}
	.order-details .map {
		height: 86rpx;
		font-size: 30rpx;
		color: #282828;
		line-height: 86rpx;
		border-bottom: 1px solid #f0f0f0;
		margin-top: 13rpx;
		background-color: #fff;
		padding: 0 30rpx;
	}
	.order-details .map .place {
		font-size: 26rpx;
		width: 176rpx;
		height: 50rpx;
		border-radius: 25rpx;
		line-height: 50rpx;
		text-align: center;
	}
	.order-details .map .place .iconfont {
		font-size: 27rpx;
		height: 27rpx;
		line-height: 27rpx;
		margin: 2rpx 3rpx 0 0;
	}
	.order-details .address .name .iconfont {
		font-size: 34rpx;
		margin-left: 10rpx;
	}
	.refund {
		padding: 0 30rpx 30rpx;
		margin-top: 24rpx;
		background-color: #fff;
		.title {
			display: flex;
			align-items: center;
			font-size: 30rpx;
			color: #333;
			height: 86rpx;
			border-bottom: 1px solid #f5f5f5;
			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 10rpx;
			}
		}
		.con {
			padding-top: 25rpx;
			font-size: 28rpx;
			color: #868686;
		}
	}
</style>


<style>
	.qs-btn {
		width: auto;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		border-radius: 50rpx;
		color: #fff;
		font-size: 27rpx;
		padding: 0 3%;
		color: #aaa;
		border: 1px solid #ddd;
		margin-right: 20rpx;
	}
</style>
